package jjn.acwing;

import java.util.Scanner;

/**
 * @author Jiang Jining
 * @since 2023-09-10 19:47
 */
public class Acwing778 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String line = sc.nextLine();
            String[] parts = line.split(",");
            String s = parts[0];
            String s1 = parts[1];
            String s2 = parts[2];
            int first = s.indexOf(s1);
            int second = s.lastIndexOf(s2);
            if (first < 0 || second < 0 || (first + s1.length() > second)) {
                System.out.println(-1);
            } else {
                System.out.printf("%d\n", Math.abs(second - first - s1.length()));
            }
        }
    }
}
